<template name="message">
	<li id="{{templatePrefix}}{{msg._id}}" data-id="{{msg._id}}" data-context={{actionContext}} class="message {{className}} {{ignoredClass}} {{system}} {{t}} {{own}} {{isTemp}} {{chatops}} {{collapsed}} {{customClass}}" data-username="{{msg.u.username}}" data-tmid="{{msg.tmid}}" data-groupable="{{isGroupable}}" data-date="{{date}}" data-timestamp="{{timestamp}}" data-alias="{{msg.alias}}">
		{{#if isThreadReply}}
			{{> messageThread parentMessage=parentMessage msg=msg tmid=msg.tmid class=bodyClass following=msg.following}}
			<div class="thread-replied js-open-thread">
				<button aria-label="{{msg.u.username}}" class="thumb user-card-message" data-username="{{msg.u.username}}">
					{{> avatar username=msg.u.username}}
				</button>
				<span role="button" class="js-toggle-thread-reply thread-reply-preview color-primary-font-color">
					<span class="message-body--unstyled">{{{threadMessage}}}</span>
				</span>
			</div>
		{{/if}}
		{{#unless shouldHideBody}}
			{{#if msg.avatar}}
				{{#if avatarFromUsername}}
					<button aria-label="{{msg.u.username}}" class="thumb user-card-message" data-username="{{msg.u.username}}">
						{{> avatar username=avatarFromUsername}}
					</button>
				{{else}}
					<button aria-label="{{msg.u.username}}" class="thumb user-card-message" data-username="{{msg.u.username}}">
						{{> avatar url=avatarFromMessage}}
					</button>
				{{/if}}
			{{else}}
				{{#if msg.emoji}}
					<button aria-label="{{msg.u.username}}" class="thumb user-card-message" data-username="{{msg.u.username}}">
						<div class="avatar">
							{{{renderEmoji msg.emoji}}}
						</div>
					</button>
				{{else}}
					<button aria-label="{{msg.u.username}}" class="thumb user-card-message" data-username="{{msg.u.username}}">
						{{> avatar username=msg.u.username}}
					</button>
				{{/if}}
			{{/if}}
			<div class="message-body-wrapper">
				<div class="title border-component-color color-info-font-color">
					<button type="button" class="user user-card-message color-primary-font-color" data-username="{{msg.u.username}}" tabindex="1">
						{{getName}}{{#if showUsername}} <span class="message-alias border-component-color color-info-font-color">@{{msg.u.username}}</span>{{/if}}
					</button>
					<span class="info border-component-color color-info-font-color"></span>
					{{# if showRoles }}
						{{#each role in roleTags}}
							<span class="role-tag color-secondary-color border-component-color" data-role="{{role.description}}">{{role.description}}</span>
						{{/each}}
					{{/if}}
					{{#if isBot}}
						<span class="is-bot color-secondary-color border-component-color">{{_ "Bot"}}</span>
					{{/if}}
					<time class="time" title='{{date}} {{time}}' datetime='{{date}} {{time}}'>{{time}}</time>
					{{#if showTranslated}}
						<span class="translated">
							<i class="icon-language {{#if msg.autoTranslateFetching}}loading{{/if}}" title="{{_ "Translated"}}"></i>
							<span class="translation-provider">{{ translationProvider }}</span>
						</span>
					{{/if}}
					{{#if msg.sentByEmail}}
						<span class="sent-by-email">
							<i class="icon-mail" title='{{_ "Message_sent_by_email"}}'></i>
						</span>
					{{/if}}
					{{#if edited}}
						<span class="edited" title='{{_ "edited"}} {{_ "at"}} {{editTime}} {{_ "by"}} {{editedBy}}'>
							<i class="icon-pencil{{#if $neq editedBy msg.u.username}} error-color{{/if}}" title="{{_ "Edited"}}"></i>
						</span>
					{{/if}}
					{{#if msg.pinned}}
						<span title="{{_ "Message_has_been_pinned"}}" class="pinned"><i class="icon-pin"></i></span>
					{{/if}}
					{{#if showStar}}
						<span title="{{_ "Message_has_been_starred"}}" class="starred"><i class="icon-star"></i></span>
					{{/if}}
					{{#if following }}
						{{#unless msg.tcount}}
							<span title="{{_ "Following"}}" class="following"><i class="icon-bell"></i></span>
						{{/unless}}
					{{/if}}
					{{#if msg.alert}}
						<div title="{{_ msg.alert }}" class="message-unread"></div>
					{{/if}}
					{{#if msg.private}}
						<span class="private">{{_ "Only_you_can_see_this_message"}}</span>
					{{/if}}
					{{#if fromSearch}}
						<span class="user color-info-font-color">
							{{>icon icon=roomIcon}}{{channelName}}
						</span>
					{{/if}}
					{{#if isIgnored}}
						<span class="toggle-hidden icon-right-dir" data-message="{{msg._id}}"> {{_ "Message_Ignored"}} </span>
					{{/if}}
				</div>
				<div class="body {{bodyClass}}" dir="auto" data-unread-text="{{_ "Unread_Messages"}}">
					{{#if isSnippet}}
						<div class="snippet-name">{{_ "Snippet_name"}}: {{snippetName}}</div>
					{{/if}}
					{{#if msg.blocks}}
						<div class='rc-ui-kit'>
							{{> Blocks blocks=msg.blocks rid=msg.rid mid=msg._id}}
						</div>
					{{else}}
						{{# if enableMessageParserEarlyAdoption }}
							{{> MessageBody tokens=msg.md mentions=msg.mentions }}
						{{else}}
							{{{body}}}
						{{/if}}
					{{/if}}
					{{#if msg.location}}
						{{> messageLocation location=msg.location}}
					{{/if}}
				</div>
			</div>

			{{#if hasOembed}}
				{{#each msg.urls}}
					{{injectMessage . ../msg}}
					{{injectSettings . ../settings}}
					{{injectIndex . @index}}
					{{> oembedBaseWidget}}
				{{/each}}
			{{/if}}
			{{#if hasAttachments}}
				{{> reactAttachments attachments=msg.attachments file=msg.file }}
			{{/if}}


			{{#with readReceipt}}
				<div class="read-receipt {{readByEveryone}}">
					{{> icon icon="check" }}
				</div>
			{{/with}}
			{{#unless hideMessageActions}}
				<div class="message-actions">

					<div class="message-actions__buttons">
						{{#each action in messageActions 'message'}}
							<button class="message-actions__button"  data-message-action="{{action.id}}" title="{{_ action.label}}">
									{{> icon block="message-actions__button-icon" icon=action.icon}}
							</button>
						{{/each}}
					</div>
					<div class="message-actions__menu" aria-haspopup="true">
						{{> icon block="message-actions__menu-icon" icon="menu"}}
					</div>
				</div>
			{{/unless}}
			{{#unless hideActionLinks}}
				{{> MessageActions mid=msg._id actions=actionLinks runAction=(actions.runAction msg)}}
			{{/unless}}
			{{#unless hideReactions}}
			<ul class="reactions">
				{{#each reaction in reactions}}
					<li data-emoji="{{reaction.emoji}}" {{markUserReaction reaction}}>
						<span class="reaction-emoji">{{{renderEmoji reaction.emoji}}}</span>
						<span class="reaction-count">{{reaction.count}}</span>
						<span class="people" style="font-weight: bold">
							{{reaction.usernames}} <span style="color: #aaa;">{{reaction.reaction}}</span>
						</span>
					</li>
				{{/each}}
				{{#unless hideAddReaction}}
					<li class="add-reaction">
						<span class="icon-people-plus"></span>
					</li>
				{{/unless}}
			</ul>
			{{/unless}}

			{{#if msg.drid}}
				{{> DiscussionMetric count=msg.dcount drid=msg.drid lm=msg.dlm openDiscussion=actions.openDiscussion }}
			{{/if}}

			{{#if $and settings.showReplyButton msg.tcount}}
			    {{> ThreadMetric counter=msg.tcount following=following lm=msg.tlm rid=msg.rid mid=msg._id unread=unread mention=mention all=all openThread=actions.openThread }}
			{{/if}}

			{{#if broadcast}}
			 	{{> BroadCastMetric mid=msg._id username=msg.u.username replyBroadcast=actions.replyBroadcast }}
			{{/if}}
		{{/unless}}
	</li>
</template>
